package com.sample.rx.fragment;

import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.loyal.rx.RxPermission;
import com.sample.rx.base.BasicFragment;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseFragment extends BasicFragment implements RxPermission.MultipleCallback, RxPermission.SingleCallback {
    private RxPermission permission;
    private Unbinder unbinder;

    @Override
    public void bindViews(View view) {
        if (null == permission)
            permission = RxPermission.getInstance();
        unbinder = ButterKnife.bind(this, view);
    }

    @Override
    public void unbind() {
        if (null != unbinder)
            unbinder.unbind();
    }

    /**
     * 用于单项权限申请
     */
    public void singlePermission(int code, final RxPermission.SingleCallback listener, String... permissions) {
        Log.e("singlePermission: ", "" + (permission.hashCode()));
        if (null == permission)
            return;
        permission.with(this).single(code, listener, permissions);
    }

    public void multiplePermissions(final RxPermission.MultipleCallback listener, String... permissions) {
        if (null == permission)
            return;
        permission.with(this).multiple(listener, permissions);
    }

    @Override
    public void onSingleCallback(int code, boolean b, Throwable e) {

    }

    @Override
    public void onMultipleCallback(@NonNull List<String> list,
                                   @NonNull List<String> list1,
                                   @Nullable Throwable e) {

    }
}
